﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using iLangl.Security.WCFAutenticationManager;

namespace iLangl.Security
{
	public class CustomerAuthenticationService : IAuthenticationService
	{
		public string CreateSession(string login, string password)
		{
			return AuthenticationService.CreateSession(login, password);
		}

		public String RegisterUser(string userName, string password)
		{
			return  AuthenticationService.RegisterUser(userName, password);
		}

		public bool IsAuthenticated(string sessionKey)
		{
			return AuthenticationService.IsAuthenticated(sessionKey);
		}

		public string GetUserName(string sessionKey)
		{
			return AuthenticationService.GetUserName(sessionKey);
		}

		private AuthenticationServiceClient AuthenticationService
		{
			get
			{

				BasicHttpBinding binding = new BasicHttpBinding();
				binding.MaxReceivedMessageSize = 104857600;
				EndpointAddress address = new EndpointAddress("http://localhost:8080/ilangl/security"); //TODO: Remove hardcoded url
				AuthenticationServiceClient authenticationService = new AuthenticationServiceClient(binding, address);
				return authenticationService;
			}
		}


		public string GetUserId(string sessionKey)
		{
			return GetUserId(sessionKey);
		}
	}
}
